package com.web.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;

import com.web.config.JWTConfig;

/**
 * 登录拦截器
 * @author Evi
 *
 */
public class LoginInterceptor implements HandlerInterceptor {
	public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception {
		System.out.println("进入登录拦截器");
		// 从请求头当中获取
		String token = req.getHeader(JWTConfig.AUTH_HEAD_NAME);
		// 校验令牌
		boolean validToken = JWTConfig.validToken(token);
		if (!validToken) {
			req.getRequestDispatcher("/api/error/notauth").forward(req, res);
		}
		return validToken;
	}

}
